package com.example.flowable.controller;

import com.example.flowable.model.ResultDTO;
import com.example.flowable.model.User;
import com.example.flowable.service.UserService;
import java.util.List;
import org.flowable.engine.repository.Deployment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "add")
    @ResponseBody
    public ResultDTO<Void> add(@RequestBody User user) {
        userService.addUser(user);
        return new ResultDTO<Void>().buildResultDTO(200,"sucess",null,null);
    }

    @RequestMapping(value = "list")
    @ResponseBody
    public ResultDTO<List<User>> list() {
        List<User> users = userService.queryUserList(new User());
        return new ResultDTO<List<User>>().buildResultDTO(200,"sucess",users, users.size());
    }

    @RequestMapping(value = "remove")
    @ResponseBody
    public ResultDTO<Void> remove(@RequestBody User user) {
        userService.deleteUser(user);
        return new ResultDTO<Void>().buildResultDTO(200,"sucess",null,null);
    }
}
